﻿/*
COPYRIGHT (C) 2011-2013 Raynald Messié

THIS FILE IS PART OF SCRUMPILOT.

SCRUMPILOT IS FREE SOFTWARE: YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF 
THE GNU LESSER GENERAL PUBLIC LICENSE VERSION v2.1 AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION.

SCRUMPILOT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY; WITHOUT
EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU LESSER
GENERAL PUBLIC LICENSE FOR MORE DETAILS.

YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE ALONG WITH SCRUMPILOT. 
IF NOT, SEE <HTTP://WWW.GNU.ORG/LICENSES/>.
*/
using System;
using ScrumPilot.Domain.Models;
using ScrumPilot.TFSHelpers;
using WorkItem = Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem;

namespace ScrumPilot.Domain.Helpers
{
    public static class Helpers
    {
        // Todo : rewrite into an operator MapTo of workitem
        public static T CastTFSWorkItem<T>(this WorkItem wie, TFSServices tfs, String projectName, Boolean loadParent, Boolean inSameIteration = false)
            where T : Models.WorkItem, new()
        {
            WorkItem parentWorkItem = loadParent ? wie.GetParentWorkItem(tfs) : null;

            var wit = new T
                          {
                              ID = wie.Id,
                              Date = wie.ChangedDate,
                              CreateDate = wie.CreatedDate,
                              CreatedBy = wie.CreatedBy,
                              AreaID = wie.AreaId,
                              IterationID = wie.IterationId,
                              ProjectID = wie.Project.Id,
                              Name = wie.Title,
                              ProjectName = !String.IsNullOrEmpty(projectName) ? projectName : wie.Project.Name,
                              Description = wie.Description ?? "",
                              Type = wie.Type.ToString(),
                              State = wie.State,
                              Score = wie.GetScrumPilotScore(),
                              Url = wie.Uri.ToString(),
                              ParentName = parentWorkItem == null ? "" : parentWorkItem.Title,
                              ParentType = parentWorkItem == null ? "" : parentWorkItem.Type.Name,
                              ParentUrl = parentWorkItem == null ? "" : parentWorkItem.Uri.ToString(),
                              AssignedTo = wie.GetAssignedTo()
                          };
            if (wit is UserStory)
            {
                wit.CompleteInit(wie, tfs, inSameIteration);
            }
            return wit;
        }

        public static String[] WorkItemStateString =
            {
                "Todo",
                "In Progress",
                "To Test",
                "Done",
                "Reopen"
            };

        public static void SetAssignedTo<T>(T wie, user usr) where T : IIWorkItem
        {
            if (usr != null)
            {
                wie.AssignedTo = usr.name;
                wie.AssignedToID = usr.userid;
            }
        }

    }

    public enum ExpertLevelScoring
    {
        Easy = 1, Normal = 3, Hard = 5
    }
    public enum TaskPriorityScoring
    {
        Low = 1, Normal = 3, High = 5
    }
    public enum TaskDurationScroring
    {
        Short = 1, Normal = 3, Long = 5
    }
    public enum UserStoryRank
    {
        Must = 999, Should = 1999, Could = 2999
    }

}